package cn.xspace.wnx.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import java.util.ArrayList;

import com.xspace.android.xafcommon.base.BaseActivity;

import cn.xspace.library.util.BldNavigation;
import cn.xspace.wnx.R;
import cn.xspace.chatui.bean.MsgRecordEntity;
import cn.xspace.wnx.fragment.ImageLargeFragment;

/**
 * Created by Administrator on 2016/11/7.
 */

public class ImageLargerActivity extends BaseActivity {
    public static final String IMAGE_LIST = "imageList";
    public static final String IMAGE_INDEX = "imageIndex";
    private ViewPager mViewpager;
    private int pageIndex;
    private ArrayList<MsgRecordEntity> dataList = new ArrayList<>();

    @Override
    protected void getIntentData() {
        super.getIntentData();
        Bundle mbunle = getIntent().getBundleExtra(BldNavigation.KEY_BUNDLER);
        dataList = (ArrayList<MsgRecordEntity>) mbunle.getSerializable(IMAGE_LIST);
        pageIndex = mbunle.getInt(IMAGE_INDEX, 0);
    }

    @Override
    protected void initData() {
        super.initData();
    }

    @Override
    protected void initEvent() {
        super.initEvent();
    }

    @Override
    protected void initView() {
        super.initView();
        setContentView(R.layout.activity_image_larger);
    }

    @Override
    protected void initFindViewById() {
        super.initFindViewById();
        mViewpager = (ViewPager) findViewById(R.id.viewpager);
        mViewpager.setAdapter(new ViewPagerAdapter(getSupportFragmentManager()));
        mViewpager.setCurrentItem(pageIndex);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    private class ViewPagerAdapter extends FragmentPagerAdapter {


        public ViewPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return dataList.size();
        }

        @Override
        public Fragment getItem(int position) {
            return ImageLargeFragment.newInstance(dataList.get(position));
        }

    }
}
